package com.zenithsun.pic.picsubject.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.syzg.common.service.impl.BaseServiceImpl;
import com.syzg.core.page.DefaultPageResult;
import com.syzg.core.page.PageResult;
import com.zenithsun.pic.picsubject.service.PicsubjectService;
import com.zenithsun.pic.picsubject.dao.PicsubjectDAO;
import com.zenithsun.pic.picsubject.model.Picsubject;

@Service("picsubjectService")
public class PicsubjectServiceImpl extends BaseServiceImpl<Picsubject> implements PicsubjectService {
    
    private PicsubjectDAO picsubjectDAO = null;

    @Resource
	public void setPicsubjectDAO(PicsubjectDAO picsubjectDAO) {
		this.setDAO(picsubjectDAO);
		this.picsubjectDAO = picsubjectDAO;
	}
    
    /**
	 * 查看图片库信息
	 * @param id ID
	 * @return
	 * @throws Exception
	 */
    @Override
    public Picsubject findPicsubjectById(String id) throws Exception {
    	// TODO Auto-generated method stub
    	Picsubject ps = (Picsubject)super.findObjectById(id);
    	return ps;
    }
    
    /**
	   * 我的图片库分页
	   * @param pageNo 当前页
	   * @param limit 页行数
	   * @param pics
	   * @return
	   * @throws Exception
	   */
    @Override
    public PageResult findPicSubjectByList(int pageNo, int limit,Picsubject pics,String year,String month)  throws Exception{
    	//搜索日期处理
    	String startDate = null;
    	String endDate = null;
    	if(year!=null&&year!=""){
    		if(month!=null&&month!=""){
    			startDate = year+"-"+month+"-01 00:00:00";
    			endDate = year+"-"+month+"-31 23:59:59";
    		}else{
    			startDate = year+"-01-01 00:00:00";
    			endDate = year+"-12-31 23:59:59";		
    		}
    	}
    	int totalCount = this.picsubjectDAO.getPicsubjectCount(pics,startDate,endDate);
    	List items = this.picsubjectDAO.findPicsubjectList(pageNo, limit,pics,startDate,endDate);
		PageResult pageResult = new DefaultPageResult(items, totalCount, (pageNo - 1) * limit, limit);
		return pageResult;
    }
	@Override
	public PageResult findSharePicSubjectByList(int pageNo, int limit,
			Picsubject pics) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
